//
//  MyViewController.m
//  DaHaiDouBan
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 Wang Dahai. All rights reserved.
//

#import "MyViewController.h"
#import "LoginViewController.h"
#import "DataBaseSingleton.h"
#import "Singleton.h"
#import "MyActivityViewController.h"
#import "MyMovieViewController.h"
@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain) UITableView *myTableView;
@property (nonatomic, retain) NSMutableArray *array;

@end

@implementation MyViewController
- (void)dealloc
{
    [_myTableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"我的";
    
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButton:)] autorelease];
    
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"登录" style: UIBarButtonItemStylePlain target:self action:@selector(leftBarButton:)] autorelease];
    
    self.myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [_myTableView release];
    
    self.array = [NSMutableArray arrayWithObjects:@"我的活动",@"我的电影",@"清理缓存", nil];
    

    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];



}
//注销
-(void)rightBarButton:(UIBarButtonItem *)rightBtn
{
  
        
}
//登录
-(void)leftBarButton:(UIBarButtonItem *)leftBtn
{
//    LoginViewController *logVC = [[LoginViewController alloc] init];
//    
//    UINavigationController *logNaVC = [[UINavigationController alloc] initWithRootViewController:logVC];
//    
//    [self presentViewController:logNaVC animated:YES completion:^{
//        
//        
//    }];
//    
//    [logVC release];
//    [logNaVC release];
    
    if(![Singleton shareSingleton].isLogin){
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        UINavigationController *naGC = [[UINavigationController alloc] initWithRootViewController:loginVC];
        [self presentViewController:naGC animated:YES completion:nil];
        [loginVC release];
        self.navigationItem.leftBarButtonItem.enabled = NO;
    }

    
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.array.count;
    
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellIdetifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdetifier];
    cell.textLabel.text = [self.array objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:20];
    return cell;
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
    
    MyActivityViewController *myActivie = [[MyActivityViewController alloc] init];
    
    [self.navigationController pushViewController:myActivie animated:YES];
    
    [myActivie release];
    
    
    
    
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
